package org.atovio.coolexam.mapper;

import org.apache.ibatis.annotations.*;
import org.atovio.coolexam.entity.ExamPaperAnswer;

import java.util.List;
import java.util.Map;

public interface ExamPaperAnswerMapper {

    @Insert("""
            insert into t_exam_paper_answer (id, exam_paper_id, system_score, user_score,
            correct_count, status, create_user_id,create_time)
            values (null, #{examPaperId}, #{systemScore},#{userScore},#{correctCount},#{status},#{createUserId},#{createTime});
            """)
    int insert(ExamPaperAnswer examPaperAnswer);

    @Select("select * from t_exam_paper_answer;")
    List<ExamPaperAnswer> selectAll();

    @Select("select * from t_exam_paper_answer where id = #{id};")
    ExamPaperAnswer selectById(Integer id);

    @Select("select * from t_exam_paper_answer where exam_paper_id = #{examPaperId};")
    List<ExamPaperAnswer> selectByExamPaperId(Integer examPaperId);

    @Select("select * from t_exam_paper_answer where create_user_id = #{createUserId};")
    List<ExamPaperAnswer> selectByCreateUserId(Integer createUserId);

    @Select(("select * from t_exam_paper_answer where status = #{status}"))
    List<ExamPaperAnswer> selectByStatus(Integer status);

    /**
     * 根据自定义条件查询记录条数
     * @param criteria 自定义条件
     * @return 记录条数
     */
    int selectCountSelective(@Param("criteria") Map<String, Object> criteria);

    /**
     * 根据自定义条件查询记录条数
     * @param criteria 自定义条件
     * @return 记录条数
     */
    List<ExamPaperAnswer> selectSelective(@Param("criteria") Map<String, Object> criteria);

    @Update("update t_exam_paper_answer set system_score = #{systemScore} where id = #{id};")
    int updateSystemScoreById(Integer id, Integer systemScore);

    @Update("update t_exam_paper_answer set user_score = #{userScore} where id = #{id};")
    int updateUserScoreById(Integer id, Integer userScore);

    @Update("update t_exam_paper_answer set correct_count = #{correctCount} where id = #{id};")
    int updateCorrectCountById(Integer id, Integer correctCount);

    @Update("update t_exam_paper_answer set status = #{status} where id = #{id};")
    int updateStatusById(Integer id, Integer status);

    @Delete("delete from t_exam_paper_answer where id = #{id};")
    int deleteById(Integer id);

}
